package cn.neusoft.neusoft_fz.service;

import com.google.gson.Gson;
import lombok.extern.slf4j.Slf4j;
import org.example.entity.Invoice;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Slf4j
@Service
public class InvoiceConsumer {
    @Autowired
    InvoiceService invoiceService;

    @RabbitListener(queues = "myQueue")
    public void listen(String message) {
        try {
            Thread.sleep(5000);
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
        Gson gson = new Gson();
        Invoice invoice = gson.fromJson(message, Invoice.class);
        log.info(invoice.toString());
        log.info("Received a message from the queue. Message: {}", message);
        invoice.setInvoiceStatus("已开票");
        invoiceService.updateById(invoice);
    }
}


